package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 排序字符串
 */
public class SortListDemo3 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("ada");
        list.add("tom");
        list.add("jerry");
        list.add("rose");
        list.add("jack");
        list.add("MIKE");
        list.add("KOBE");
        list.add("JAMES");
        list.add("hanmeimei");
        System.out.println(list);//[ada, tom, jerry, rose, jack, MIKE, KOBE, JAMES, hanmeimei]
        Collections.sort(list);
        System.out.println(list);//[JAMES, KOBE, MIKE, ada, hanmeimei, jack, jerry, rose, tom]

        List<String> list1 = new ArrayList<>();
        list1.add("苍老师");
        list1.add("传奇");
        list1.add("小泽老师");
        list1.add("小艾老师");
        list1.add("张雄辉老师");
        System.out.println(list1);//[苍老师, 传奇, 小泽老师, 小艾老师, 张雄辉老师]
        Collections.sort(list1,(s1,s2)->
                s1.length()-s2.length()
                );
        System.out.println(list1);//[传奇, 苍老师, 小泽老师, 小艾老师, 张雄辉老师]

        Collections.sort(list1,(s1,s2)->
                s2.length()-s1.length()
        );
        System.out.println(list1);//[张雄辉老师, 小泽老师, 小艾老师, 苍老师, 传奇]
    }
}
